package com.xhj.joffer.aa;
import org.junit.Test;
/**
 * @author haijianxia pure_xhj@163.com
 * @Date 2021-09-22
 * @Time 16:49
 */
public class Find1InBinary {
  public static void main(String[] args) {
	  int i1=4;
	  byte b1=(byte)i1;
	  byte b2=Byte.valueOf(Integer.toBinaryString(i1));
	  byte b3=Byte.parseByte(Integer.toBinaryString(i1));

    System.out.println(" = " + b1);
    System.out.println("b2 = " + b2);
    System.out.println("b3 = " + b3);

	  System.out.println("====================================================");
    System.out.println("test01(4) = " + test01(4));
  }
  
  /** 思路一: String */
  @Test
  public static int test01(int n) {
  	System.out.println("\n=============test01==============");
  	System.out.println("思路一: String");
  	long time01 = System.currentTimeMillis();
  	
  	int result =0;
	  char[] chars = Integer.toBinaryString(n).toCharArray();
	  for (int i = 0; i < chars.length; i++) {
		  if(chars[i]=='1'){
			  result++;
		  }
	  }

  	long time0101  = System.currentTimeMillis() - time01;
  	System.out.println("test01 耗时 =  " + time0101  + "ms");
  	System.out.println("=================================");
  
  	return result;
  }
}
